//
//  NightTableviewCell.m
//  HandWork
//
//  Created by 王阳阳 on 16/2/27.
//  Copyright © 2016年 www.lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "NightTableviewCell.h"

@implementation NightTableviewCell
-(void)dealloc
{
    [_namelabel release];
    
    [_sw release];
    [super dealloc];
}
#pragma mark - 初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        //tableview名字
        self.namelabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.namelabel];
        [self.namelabel release];


        //switch
        self.sw = [[UISwitch alloc]init];
        [self.contentView addSubview:self.sw];
        [_sw release];
    }
    return self;
}
#pragma mark - 布局
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.namelabel.frame = CGRectMake(10, 5, 80, 30);//名字
    
    self.sw.frame = CGRectMake( [UIScreen mainScreen].bounds.size.width - 100, 5, 80, 30);
    self.sw.tag = 6000;
    [_sw addTarget:self action:@selector(swcAction:) forControlEvents:UIControlEventValueChanged];
}

- (void)swcAction:(UISwitch *)swc
{
    if (swc.tag == 6000) {
        if (swc.isOn) {
            [[NSUserDefaults standardUserDefaults] setObject:@"Night" forKey:@"mode"];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"模式" object:@"Night" userInfo:nil];
        }else{
            [[NSNotificationCenter defaultCenter] postNotificationName:@"模式" object:@"day" userInfo:nil];
            [[NSUserDefaults standardUserDefaults] setObject:@"day" forKey:@"mode"];
        }
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
